<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 设置
 */
class Settin extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';

    /**
     * 支付密码
     *
     * @param $mobile string 手机号
     * @param $paymentPassword string  新密码
     * @param $captcha string 验证码
     */

    public function paymentPassword()
    {
        $mobile = input("mobile");
        $paymentPassword = input("paymentPassword");
        $captcha = input("captcha");
        if (!$paymentPassword || !$captcha) {
            $this->error(__('Invalid parameters'));
        }
        if (!\think\Validate::regex($mobile, "^1\d{10}$")) {
            $this->error(__('Mobile is incorrect'));
        }
        $user = \app\common\model\User::getByMobile($mobile);
        if (!$user) {
            $this->error(__('User not found'));
        }
//        $ret = \app\api\library\Sms::check($mobile, $captcha, 'payment');
//        if (!$ret) {
//            $this->error(__('Captcha is incorrect'));
//        }
        $user->payment_password = $this->auth->getEncryptPassword($paymentPassword, $user['salt']);
        $user->save();
        $this->success('设置成功');
    }
}